<?php

class Hot extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->service('Service_hot');
        $this->load->driver('cache');
    }

    public function index()
    {
        $rankingList = [100038,100001,100007,100121,100135,100045,100003,100006,100008,100015,100017,100018,100020,100023,100037,100065,100069,100070];
        $list = [];
        foreach($rankingList as $ranking) {
            $res = $this->Service_hot->api(['rid' => $ranking]);
            $list[$ranking] = $res;
        }

        $this->assign('title', '今日热榜');
        $this->assign('key', '今日热榜');
        $this->assign('list', $list);
        $this->display("hot/ranking.tpl");
    }

    public function api()
    {
        $params = $this->getParams();
        $result = $this->Service_hot->api($params);
        json($result);
    }

    public function test()
    {
        $rankingList = [];
        for($i = 100000; $i <= 100138; $i++) {
            $rankingList[] = $i;
        }

        $list = [];
        foreach($rankingList as $ranking) {
            $res = $this->Service_hot->api(['rid' => $ranking]);
            $list[$ranking] = [$res['title'], $res['subtitle']];
        }
        echo json_encode($list);
    }
}